<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
<!--          <a-col :xl="10" :lg="11" :md="12" :sm="24">-->
<!--            <a-form-item label="时间筛选">-->
<!--              <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" class="query-group-cust" v-model="queryParam.createTime_begin"></j-date>-->
<!--              <span class="query-group-split-cust"></span>-->
<!--              <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" class="query-group-cust" v-model="queryParam.createTime_end"></j-date>-->
<!--            </a-form-item>-->
<!--          </a-col>-->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="工具箱编号">
              <a-input placeholder="请输入工具箱编号" v-model="queryParam.toolboxNum"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="标签">
              <a-input placeholder="请输入标签" v-model="queryParam.toolNum"></a-input>
            </a-form-item>
          </a-col>
<!--          <template v-if="toggleSearchStatus">-->
<!--            <a-col :xl="6" :lg="7" :md="8" :sm="24">-->
<!--              <a-form-item label="物料码">-->
<!--                <a-input placeholder="请输入物料码" v-model="queryParam.toolCode"></a-input>-->
<!--              </a-form-item>-->
<!--            </a-col>-->
<!--            <a-col :xl="6" :lg="7" :md="8" :sm="24">-->
<!--              <a-form-item label="规格">-->
<!--                <a-input placeholder="请输入规格" v-model="queryParam.toolSpecifications"></a-input>-->
<!--              </a-form-item>-->
<!--            </a-col>-->
<!--            <a-col :xl="6" :lg="7" :md="8" :sm="24">-->
<!--              <a-form-item label="工具类别">-->
<!--                <a-input placeholder="请输入工具类别" v-model="queryParam.toolType"></a-input>-->
<!--              </a-form-item>-->
<!--            </a-col>-->
<!--          </template>-->
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
<!--      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>-->
      <a-button type="primary" icon="download" @click="handleExportXls('工具管理')">导出</a-button>
<!--      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">-->
<!--        <a-button type="primary" icon="import">导入</a-button>-->
<!--      </a-upload>-->
      <!-- 高级查询区域 -->
      <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
      <!--图表：柱形图、饼状图、折线图-->
      <a-button @click="showRadarChart" type="primary"><a-icon type="radar-chart" />柱状图</a-button>
      <a-button @click="showPieChart" type="primary"><a-icon type="pie-chart" />饼状图</a-button>
      <a-button @click="showAreaChart" type="primary"><a-icon type="area-chart" />曲线图</a-button>
    </div>

    <div>
      <a-modal
        title="Title"
        :visible="visible"
        :confirm-loading="confirmLoading"
        @ok="handleOk"
        @cancel="handleCancel"
      >
        <j-form-container>
          <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
            <a-form-model-item label="工具id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="toolAdminId">
              <a-input disabled v-model="model.toolAdminId" placeholder="请输入工具id"  ></a-input>
            </a-form-model-item>
            <a-form-model-item label="工具箱" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="toolboxId">
              <a-select default-value="lucy" style="width: 100%;margin-top: 20px" v-model="model.toolboxId">
                <a-select-option  v-for="(val,key) in toolboxResult" :key="key" :value="val.id">
                  {{val.toolboxName}}
                </a-select-option>
              </a-select>
            </a-form-model-item>
          </a-form-model>
        </j-form-container>
      </a-modal>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
<!--          <a @click="handleEdit(record)">编辑</a>-->

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="showModal(record.id)">选择工具箱</a>
              </a-menu-item>
<!--              <a-menu-item>-->
<!--                <a @click="handleDetail(record)">详情</a>-->
<!--              </a-menu-item>-->
              <a-menu-item>
                <a @click="lookToolValue(record.toolNum)">查看工具详细数据</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <a-modal ref="toolDetailInfo" v-model="toolInfoVisible" title="工具详细数据" @ok="toolInfoOk">
      <div v-html="toolInfoHtml"></div>
    </a-modal>
    <tool-admin-chart-modal ref="modalRadarChart" mark="radar" :selection-rows="selectionRows" :chartTitle="title.radarTitle"></tool-admin-chart-modal>
    <tool-admin-chart-modal ref="modalPieChart" mark="pie" :selection-rows="selectionRows" :chartTitle="title.pieTitle"></tool-admin-chart-modal>
    <tool-admin-chart-modal ref="modalAreaChart" mark="area" :selection-rows="selectionRows" :chartTitle="title.areaTitle"></tool-admin-chart-modal>
    <tool-admin-modal ref="modalForm" @ok="modalFormOk"></tool-admin-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ToolAdminModal from './modules/ToolAdminModal'
  import { httpAction, getAction ,postAction} from '@/api/manage'
  import ToolAdminChartModal from './chart/ToolAdminChartModal'

  export default {
    model:{},
    name: 'ToolAdminList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      ToolAdminModal,
      ToolAdminChartModal
    },
    data () {
      return {
        toolInfoHtml:'',
        toolInfoVisible:false,
        toolboxResult:{},
        id : "",
        model:{toolboxId:"",toolAdminId:""},
        dataValue:[{name:123,sex:1},{name:456,sex:2},{name:789,sex:3}],
        visible: false,
        confirmLoading: false,
        description: '工具管理管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'创建日期',
            align:"center",
            dataIndex: 'createTime'
          },
          {
            title:'创建人',
            align:"center",
            dataIndex: 'createBy'
          },
          {
            title:'工具箱编号',
            align:"center",
            dataIndex: 'toolboxNum'
          },
          {
            title:'工具标签',
            align:"center",
            dataIndex: 'toolNum'
          },
          // {
          //   title:'工具名称',
          //   align:"center",
          //   dataIndex: 'toolName'
          // },
          // {
          //   title:'物料码',
          //   align:"center",
          //   dataIndex: 'toolCode'
          // },
          // {
          //   title:'数量',
          //   align:"center",
          //   dataIndex: 'toolNum'
          // },
          // {
          //   title:'规格',
          //   align:"center",
          //   dataIndex: 'toolSpecifications'
          // },
          // {
          //   title:'工具类别',
          //   align:"center",
          //   dataIndex: 'toolType'
          // },
          // {
          //   title:'其他',
          //   align:"center",
          //   dataIndex: 'other'
          // },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        title:{
            radarTitle:"工具报警信息柱状图数据分析",
            pieTitle:"工具报警信息饼图数据分析",
            areaTitle:"工具报警信息折线走势分析"
        },
        url: {
          list: "/tooladmin/toolAdmin/list",
          delete: "/tooladmin/toolAdmin/delete",
          deleteBatch: "/tooladmin/toolAdmin/deleteBatch",
          exportXlsUrl: "/tooladmin/toolAdmin/exportXls",
          importExcelUrl: "tooladmin/toolAdmin/importExcel",

        },
        dictOptions:{},
        superFieldList:[],
        validatorRules: {
          toolboxId: [
            { required: true, message: '请输入工具箱id!'},
          ],
          toolAdminId: [
            { required: true, message: '请输入工具id!'},
          ],
        },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      //解析工具标签数据
      lookToolValue:function(record){
        this.tags = {
          "tags":record
        }
        this.toolInfoHtml = ""
        postAction("/encodingrules/encodingRules/encodingTags",this.tags).then(res=>{
          if (res.result != null && res.result.length>0){
            this.$message.error(res.result);
            return;
          }
          if(res==null){
            this.$message.warn("标签信息过多，详情请查看工具管理")
            return;
          }
          /*alert(res)*/
          //厂家信息
          this.toolInfoHtml += "<p>厂家信息："+res.factoryInfo+"</p>"
          //工具名称
          this.toolInfoHtml += "<p>工具名称："+res.toolName+"</p>"
          //工具规格型号
          this.toolInfoHtml += "<p>工具规格型号："+res.toolSpecifications+"</p>"
          //工具类别
          this.toolInfoHtml += "<p>工具类别："+res.toolType+"</p>"
          //所属箱子ID号
          this.toolInfoHtml += "<p>所属箱子ID号："+res.toolboxId+"</p>"
          //工具物料码
          this.toolInfoHtml += "<p>工具物料码："+res.toolCode+"</p>"
          //(单位)局
          this.toolInfoHtml += "<p>(单位)局："+res.office+"</p>"
          //(单位)段
          this.toolInfoHtml += "<p>(单位)段："+res.section+"</p>"
          //(单位)车间
          this.toolInfoHtml += "<p>(单位)车间："+res.workshop+"</p>"
          //(单位)工区
          this.toolInfoHtml += "<p>(单位)工区："+res.workArea+"</p>"
          //工具采购时间：年
          this.toolInfoHtml += "<p>工具采购时间(年)："+res.buyYear+"</p>"
          //工具采购时间：月
          this.toolInfoHtml += "<p>工具采购时间(月)："+res.buyMonth+"</p>"
          this.toolInfoVisible = true
          console.log(res);
        }).catch(err=>{
          this.toolInfoHtml += "请求失败，暂无数据可查看"
          console.log(err);
        })
      },
      toolInfoOk(){
        this.toolInfoVisible = false
      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'datetime',value:'createTime',text:'创建日期'})
        fieldList.push({type:'string',value:'toolName',text:'工具名称',dictCode:''})
        fieldList.push({type:'string',value:'toolNum',text:'物料码',dictCode:''})
        fieldList.push({type:'string',value:'toolSpecifications',text:'规格',dictCode:''})
        fieldList.push({type:'string',value:'toolType',text:'工具类别',dictCode:''})
        fieldList.push({type:'string',value:'other',text:'其他',dictCode:''})
        this.superFieldList = fieldList
      },
      showModal(id) {
        console.log("id="+id)
        this.model.toolAdminId = id;
        this.visible = true;
        getAction('/toolbox/toolbox/list',null).then(res=>{
          console.log("success:" + res.result.records[0].id)
          this.toolboxResult = res.result.records;
        }).catch(res=>{
          console.log("error : " + res)
        })
      },
      handleOk(e) {
        this.$refs.form.validate(valid => {
          if (valid){
            console.log(this.model)
            this.confirmLoading = true;
            postAction('/tooltoolbox/toolToolbox/add',this.model).then(res=>{
              this.confirmLoading = false;
              this.visible = false;
              if (res.success){
                this.$message.success(res.message)
              }else {
                this.$message.warning(res.message)
              }

            }).catch(res=>{
              console.log("res="+res)
              console.log("error");
            });
          }
        })

      },
      handleCancel(e) {
        console.log('Clicked cancel button');
        this.visible = false;
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>